home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-01  |  66.8 KB  |  2,699 lines

  1. /* read.c - read a source file -
  2.    Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994
  3.    Free Software Foundation, Inc.
  4.  
  5. This file is part of GAS, the GNU Assembler.
  6.  
  7. GAS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GAS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GAS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21. #if 0
  22. #define MASK_CHAR (0xFF)    /* If your chars aren't 8 bits, you will
  23.                    change this a bit.  But then, GNU isn't
  24.                    spozed to run on your machine anyway.
  25.                    (RMS is so shortsighted sometimes.)
  26.                    */
  27. #else
  28. #define MASK_CHAR ((int)(unsigned char)-1)
  29. #endif
  30.  
  31.  
  32. /* This is the largest known floating point format (for now). It will
  33.    grow when we do 4361 style flonums. */
  34.  
  35. #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
  36.  
  37. /* Routines that read assembler source text to build spagetti in memory.
  38.    Another group of these functions is in the expr.c module.  */
  39.  
  40. /* for isdigit() */
  41. #include <ctype.h>
  42.  
  43. #include "as.h"
  44. #include "subsegs.h"
  45.  
  46. #include "obstack.h"
  47. #include "listing.h"
  48.  
  49. #ifndef TC_START_LABEL
  50. #define TC_START_LABEL(x,y) (x==':')
  51. #endif
  52.  
  53. /* The NOP_OPCODE is for the alignment fill value.
  54.  * fill it a nop instruction so that the disassembler does not choke
  55.  * on it
  56.  */
  57. #ifndef NOP_OPCODE
  58. #define NOP_OPCODE 0x00
  59. #endif
  60.  
  61. char *input_line_pointer;    /*->next char of source file to parse. */
  62.  
  63. int generate_asm_lineno = 0;    /* flag to generate line stab for .s file */
  64.  
  65. #if BITS_PER_CHAR != 8
  66. /*  The following table is indexed by[(char)] and will break if
  67.     a char does not have exactly 256 states (hopefully 0:255!)!  */
  68. die horribly;
  69. #endif
  70.  
  71. #ifndef LEX_AT
  72. /* The m88k unfortunately uses @ as a label beginner.  */
  73. #define LEX_AT 0
  74. #endif
  75.  
  76. #ifndef LEX_BR
  77. /* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
  78. #define LEX_BR 0
  79. #endif
  80.  
  81. #ifndef LEX_PCT
  82. /* The Delta 68k assembler permits % inside label names.  */
  83. #define LEX_PCT 0
  84. #endif
  85.  
  86. /* used by is_... macros. our ctype[] */
  87. const char lex_type[256] =
  88. {
  89.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    /* @ABCDEFGHIJKLMNO */
  90.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    /* PQRSTUVWXYZ[\]^_ */
  91.   0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0,    /* _!"#$%&'()*+,-./ */
  92.   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,    /* 0123456789:;<=>? */
  93.   LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,    /* @ABCDEFGHIJKLMNO */
  94.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
  95.   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,    /* `abcdefghijklmno */
  96.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */
  97.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  98.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  99.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  100.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  101.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  102.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  103.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  104. };
  105.  
  106.  
  107. /*
  108.  * In: a character.
  109.  * Out: 1 if this character ends a line.
  110.  */
  111. #define _ (0)
  112. char is_end_of_line[256] =
  113. {
  114. #ifdef CR_EOL
  115.   _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _,    /* @abcdefghijklmno */
  116. #else
  117.   _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _,    /* @abcdefghijklmno */
  118. #endif
  119.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  120. #ifdef TC_HPPA
  121.   _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* _!"#$%&'()*+,-./ */
  122.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* 0123456789:;<=>? */
  123. #else
  124.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  125.   _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _,    /* 0123456789:;<=>? */
  126. #endif
  127.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  128.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  129.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  130.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  131.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  132.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  133.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  134.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  135.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  136. };
  137. #undef _
  138.  
  139. /* Functions private to this file. */
  140.  
  141. static char *buffer;    /* 1st char of each buffer of lines is here. */
  142. static char *buffer_limit;    /*->1 + last char in buffer. */
  143.  
  144. int target_big_endian;
  145.  
  146. static char *old_buffer;    /* JF a hack */
  147. static char *old_input;
  148. static char *old_limit;
  149.  
  150. /* Variables for handling include file directory list. */
  151.  
  152. char **include_dirs;    /* List of pointers to directories to
  153.                search for .include's */
  154. int include_dir_count;    /* How many are in the list */
  155. int include_dir_maxlen = 1;/* Length of longest in list */
  156.  
  157. #ifndef WORKING_DOT_WORD
  158. struct broken_word *broken_words;
  159. int new_broken_words;
  160. #endif
  161.  
  162. char *demand_copy_string PARAMS ((int *lenP));
  163. int is_it_end_of_statement PARAMS ((void));
  164. static segT get_segmented_expression PARAMS ((expressionS *expP));
  165. static segT get_known_segmented_expression PARAMS ((expressionS * expP));
  166. static void pobegin PARAMS ((void));
  167.  
  168.  
  169. void
  170. read_begin ()
  171. {
  172.   const char *p;
  173.  
  174.   pobegin ();
  175.   obj_read_begin_hook ();
  176.  
  177.   /* Something close -- but not too close -- to a multiple of 1024.
  178.      The debugging malloc I'm using has 24 bytes of overhead.  */
  179.   obstack_begin (¬es, 5090);
  180.   obstack_begin (&cond_obstack, 990);
  181.  
  182.   /* Use machine dependent syntax */
  183.   for (p = line_separator_chars; *p; p++)
  184.     is_end_of_line[(unsigned char) *p] = 1;
  185.   /* Use more.  FIXME-SOMEDAY. */
  186. }
  187.  
  188. /* set up pseudo-op tables */
  189.  
  190. struct hash_control *po_hash;
  191.  
  192. static const pseudo_typeS potable[] =
  193. {
  194.   {"abort", s_abort, 0},
  195.   {"align", s_align_ptwo, 0},
  196.   {"ascii", stringer, 0},
  197.   {"asciz", stringer, 1},
  198. /* block */
  199.   {"byte", cons, 1},
  200.   {"comm", s_comm, 0},
  201.   {"data", s_data, 0},
  202. #ifdef S_SET_DESC
  203.   {"desc", s_desc, 0},
  204. #endif
  205. /* dim */
  206.   {"double", float_cons, 'd'},
  207. /* dsect */
  208.   {"eject", listing_eject, 0},    /* Formfeed listing */
  209.   {"else", s_else, 0},
  210.   {"end", s_end, 0},
  211.   {"endif", s_endif, 0},
  212. /* endef */
  213.   {"equ", s_set, 0},
  214. /* err */
  215. /* extend */
  216.   {"extern", s_ignore, 0},    /* We treat all undef as ext */
  217.   {"appfile", s_app_file, 1},
  218.   {"appline", s_app_line, 0},
  219.   {"file", s_app_file, 0},
  220.   {"fill", s_fill, 0},
  221.   {"float", float_cons, 'f'},
  222.   {"global", s_globl, 0},
  223.   {"globl", s_globl, 0},
  224.   {"hword", cons, 2},
  225.   {"if", s_if, 0},
  226.   {"ifdef", s_ifdef, 0},
  227.   {"ifeqs", s_ifeqs, 0},
  228.   {"ifndef", s_ifdef, 1},
  229.   {"ifnes", s_ifeqs, 1},
  230.   {"ifnotdef", s_ifdef, 1},
  231.   {"include", s_include, 0},
  232.   {"int", cons, 4},
  233.   {"lcomm", s_lcomm, 0},
  234.   {"lflags", listing_flags, 0},    /* Listing flags */
  235.   {"list", listing_list, 1},    /* Turn listing on */
  236.   {"long", cons, 4},
  237.   {"lsym", s_lsym, 0},
  238.   {"nolist", listing_list, 0},    /* Turn listing off */
  239.   {"octa", cons, 16},
  240.   {"org", s_org, 0},
  241.   {"psize", listing_psize, 0},    /* set paper size */
  242. /* print */
  243.   {"quad", cons, 8},
  244.   {"sbttl", listing_title, 1},    /* Subtitle of listing */
  245. /* scl */
  246. /* sect */
  247.   {"set", s_set, 0},
  248.   {"short", cons, 2},
  249.   {"single", float_cons, 'f'},
  250. /* size */
  251.   {"space", s_space, 0},
  252.   {"stabd", s_stab, 'd'},
  253.   {"stabn", s_stab, 'n'},
  254.   {"stabs", s_stab, 's'},
  255.   {"string", stringer, 1},
  256. /* tag */
  257.   {"text", s_text, 0},
  258.  
  259.   /* This is for gcc to use.  It's only just been added (2/94), so gcc
  260.      won't be able to use it for a while -- probably a year or more.
  261.      But once this has been released, check with gcc maintainers
  262.      before deleting it or even changing the spelling.  */
  263.   {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
  264.   /* If we're folding case -- done for some targets, not necessarily
  265.      all -- the above string in an input file will be converted to
  266.      this one.  Match it either way...  */
  267.   {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
  268.  
  269.   {"title", listing_title, 0},    /* Listing title */
  270. /* type */
  271. /* use */
  272. /* val */
  273.   {"xstabs", s_xstab, 's'},
  274.   {"word", cons, 2},
  275.   {"zero", s_space, 0},
  276.   {NULL}            /* end sentinel */
  277. };
  278.  
  279. static void 
  280. pobegin ()
  281. {
  282.   const char *errtxt;            /* error text */
  283.   const pseudo_typeS *pop;
  284.  
  285.   po_hash = hash_new ();
  286.  
  287.   /* Do the target-specific pseudo ops. */
  288.   for (pop = md_pseudo_table; pop->poc_name; pop++)
  289.     {
  290.       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  291.       if (errtxt)
  292.     {
  293.       as_fatal ("error constructing md pseudo-op table");
  294.     }            /* on error */
  295.     }                /* for each op */
  296.  
  297.   /* Now object specific.  Skip any that were in the target table. */
  298.   for (pop = obj_pseudo_table; pop->poc_name; pop++)
  299.     {
  300.       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  301.       if (errtxt)
  302.     {
  303.       if (!strcmp (errtxt, "exists"))
  304.         {
  305. #ifdef DIE_ON_OVERRIDES
  306.           as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
  307. #endif /* DIE_ON_OVERRIDES */
  308.           continue;        /* OK if target table overrides. */
  309.         }
  310.       else
  311.         {
  312.           as_fatal ("error constructing obj pseudo-op table");
  313.         }            /* if overridden */
  314.     }            /* on error */
  315.     }                /* for each op */
  316.  
  317.   /* Now portable ones.  Skip any that we've seen already. */
  318.   for (pop = potable; pop->poc_name; pop++)
  319.     {
  320.       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  321.       if (errtxt)
  322.     {
  323.       if (!strcmp (errtxt, "exists"))
  324.         {
  325. #ifdef DIE_ON_OVERRIDES
  326.           as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
  327. #endif /* DIE_ON_OVERRIDES */
  328.           continue;        /* OK if target table overrides. */
  329.         }
  330.       else
  331.         {
  332.           as_fatal ("error constructing obj pseudo-op table");
  333.         }            /* if overridden */
  334.     }            /* on error */
  335.     }                /* for each op */
  336.  
  337.   return;
  338. }                /* pobegin() */
  339.  
  340. #define HANDLE_CONDITIONAL_ASSEMBLY()                    \
  341.   if (ignore_input ())                            \
  342.     {                                    \
  343.       while (! is_end_of_line[(unsigned char) *input_line_pointer++])    \
  344.     if (input_line_pointer == buffer_limit)                \
  345.       break;                            \
  346.       continue;                                \
  347.     }
  348.  
  349.  
  350. /*    read_a_source_file()
  351.  *
  352.  * We read the file, putting things into a web that
  353.  * represents what we have been reading.
  354.  */
  355. void 
  356. read_a_source_file (name)
  357.      char *name;
  358. {
  359.   register char c;
  360.   register char *s;        /* string of symbol, '\0' appended */
  361.   register int temp;
  362.   pseudo_typeS *pop;
  363.  
  364.   buffer = input_scrub_new_file (name);
  365.  
  366.   listing_file (name);
  367.   listing_newline ("");
  368.  
  369.   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
  370.     {                /* We have another line to parse. */
  371.       know (buffer_limit[-1] == '\n');    /* Must have a sentinel. */
  372.     contin:            /* JF this goto is my fault I admit it.
  373.                    Someone brave please re-write the whole
  374.                    input section here?  Pleeze???  */
  375.       while (input_line_pointer < buffer_limit)
  376.     {
  377.       /* We have more of this buffer to parse. */
  378.  
  379.       /*
  380.        * We now have input_line_pointer->1st char of next line.
  381.        * If input_line_pointer [-1] == '\n' then we just
  382.        * scanned another line: so bump line counters.
  383.        */
  384.       if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
  385.         {
  386.           if (input_line_pointer[-1] == '\n')
  387.         bump_line_counters ();
  388.  
  389. #if defined (MRI) || defined (LABELS_WITHOUT_COLONS)
  390.           /* Text at the start of a line must be a label, we run down
  391.          and stick a colon in.  */
  392.           if (is_name_beginner (*input_line_pointer))
  393.         {
  394.           char *line_start = input_line_pointer;
  395.           char c = get_symbol_end ();
  396.           colon (line_start);
  397.           *input_line_pointer = c;
  398.           if (c == ':')
  399.             input_line_pointer++;
  400.  
  401.         }
  402. #endif
  403.         }
  404.  
  405.  
  406.       /*
  407.        * We are at the begining of a line, or similar place.
  408.        * We expect a well-formed assembler statement.
  409.        * A "symbol-name:" is a statement.
  410.        *
  411.        * Depending on what compiler is used, the order of these tests
  412.        * may vary to catch most common case 1st.
  413.        * Each test is independent of all other tests at the (top) level.
  414.        * PLEASE make a compiler that doesn't use this assembler.
  415.        * It is crufty to waste a compiler's time encoding things for this
  416.        * assembler, which then wastes more time decoding it.
  417.        * (And communicating via (linear) files is silly!
  418.        * If you must pass stuff, please pass a tree!)
  419.        */
  420.       if ((c = *input_line_pointer++) == '\t'
  421.           || c == ' '
  422.           || c == '\f'
  423.           || c == 0)
  424.         {
  425.           c = *input_line_pointer++;
  426.         }
  427.       know (c != ' ');    /* No further leading whitespace. */
  428.       LISTING_NEWLINE ();
  429.       /*
  430.        * C is the 1st significant character.
  431.        * Input_line_pointer points after that character.
  432.        */
  433.       if (is_name_beginner (c))
  434.         {
  435.           /* want user-defined label or pseudo/opcode */
  436.           HANDLE_CONDITIONAL_ASSEMBLY ();
  437.  
  438.           s = --input_line_pointer;
  439.           c = get_symbol_end ();    /* name's delimiter */
  440.           /*
  441.            * C is character after symbol.
  442.            * That character's place in the input line is now '\0'.
  443.            * S points to the beginning of the symbol.
  444.            *   [In case of pseudo-op, s->'.'.]
  445.            * Input_line_pointer->'\0' where c was.
  446.            */
  447.           if (TC_START_LABEL(c, input_line_pointer))
  448.         {
  449.           colon (s);    /* user-defined label */
  450.           *input_line_pointer++ = ':';    /* Put ':' back for error messages' sake. */
  451.           /* Input_line_pointer->after ':'. */
  452.           SKIP_WHITESPACE ();
  453.  
  454.  
  455.         }
  456.           else if (c == '='
  457.                || (input_line_pointer[1] == '='
  458. #ifdef TC_EQUAL_IN_INSN
  459.                && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
  460. #endif
  461.                ))
  462.         {
  463.           equals (s);
  464.           demand_empty_rest_of_line ();
  465.         }
  466.           else
  467.         {        /* expect pseudo-op or machine instruction */
  468. #ifdef MRI
  469.           if (!done_pseudo (s))
  470.  
  471. #else
  472.  
  473.           pop = NULL;
  474.  
  475. #define IGNORE_OPCODE_CASE
  476. #ifdef IGNORE_OPCODE_CASE
  477.           {
  478.             char *s2 = s;
  479.             while (*s2)
  480.               {
  481.             if (isupper (*s2))
  482.               *s2 = tolower (*s2);
  483.             s2++;
  484.               }
  485.           }
  486. #endif
  487.  
  488. #ifdef NO_PSEUDO_DOT
  489.           /* The m88k uses pseudo-ops without a period.  */
  490.           pop = (pseudo_typeS *) hash_find (po_hash, s);
  491.           if (pop != NULL && pop->poc_handler == NULL)
  492.             pop = NULL;
  493. #endif
  494.  
  495.           if (pop != NULL || *s == '.')
  496.             {
  497.               /*
  498.                * PSEUDO - OP.
  499.                *
  500.                * WARNING: c has next char, which may be end-of-line.
  501.                * We lookup the pseudo-op table with s+1 because we
  502.                * already know that the pseudo-op begins with a '.'.
  503.                */
  504.  
  505.               if (pop == NULL)
  506.             pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
  507.  
  508.               /* Print the error msg now, while we still can */
  509.               if (pop == NULL)
  510.             {
  511.               as_bad ("Unknown pseudo-op:  `%s'", s);
  512.               *input_line_pointer = c;
  513.               s_ignore (0);
  514.               continue;
  515.             }
  516.  
  517.               /* Put it back for error messages etc. */
  518.               *input_line_pointer = c;
  519.               /* The following skip of whitespace is compulsory.
  520.              A well shaped space is sometimes all that separates
  521.              keyword from operands. */
  522.               if (c == ' ' || c == '\t')
  523.             input_line_pointer++;
  524.               /*
  525.                * Input_line is restored.
  526.                * Input_line_pointer->1st non-blank char
  527.                * after pseudo-operation.
  528.                */
  529.               (*pop->poc_handler) (pop->poc_val);
  530.             }
  531.           else
  532. #endif
  533.             {        /* machine instruction */
  534.               /* WARNING: c has char, which may be end-of-line. */
  535.               /* Also: input_line_pointer->`\0` where c was. */
  536.               *input_line_pointer = c;
  537.               while (!is_end_of_line[(unsigned char) *input_line_pointer]
  538. #ifdef TC_EOL_IN_INSN
  539.                  || TC_EOL_IN_INSN (input_line_pointer)
  540. #endif
  541.                  )
  542.             {
  543.               input_line_pointer++;
  544.             }
  545.  
  546.               c = *input_line_pointer;
  547.               *input_line_pointer = '\0';
  548.  
  549. #ifdef OBJ_GENERATE_ASM_LINENO
  550.               if (generate_asm_lineno == 0)
  551.             {
  552.                   if (ecoff_no_current_file())
  553.                 generate_asm_lineno = 1;
  554.             }
  555.               if (generate_asm_lineno == 1)
  556.                 {
  557.               unsigned int lineno;
  558.               char *s;
  559.               as_where (&s, &lineno);
  560.               OBJ_GENERATE_ASM_LINENO (s, lineno);
  561.                 }
  562. #endif
  563.  
  564.               md_assemble (s);    /* Assemble 1 instruction. */
  565.  
  566.               *input_line_pointer++ = c;
  567.  
  568.               /* We resume loop AFTER the end-of-line from
  569.              this instruction. */
  570.             }        /* if (*s=='.') */
  571.         }        /* if c==':' */
  572.           continue;
  573.         }            /* if (is_name_beginner(c) */
  574.  
  575.  
  576.       /* Empty statement?  */
  577.       if (is_end_of_line[(unsigned char) c])
  578.         continue;
  579.  
  580. #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
  581.       if (isdigit (c))
  582.         {
  583.           /* local label  ("4:") */
  584.           char *backup = input_line_pointer;
  585.  
  586.           HANDLE_CONDITIONAL_ASSEMBLY ();
  587.  
  588.           temp = c - '0';
  589.  
  590.           while (isdigit (*input_line_pointer))
  591.         {
  592.           temp = (temp * 10) + *input_line_pointer - '0';
  593.           ++input_line_pointer;
  594.         }        /* read the whole number */
  595.  
  596. #ifdef LOCAL_LABELS_DOLLAR
  597.           if (*input_line_pointer == '$'
  598.           && *(input_line_pointer + 1) == ':')
  599.         {
  600.           input_line_pointer += 2;
  601.  
  602.           if (dollar_label_defined (temp))
  603.             {
  604.               as_fatal ("label \"%d$\" redefined", temp);
  605.             }
  606.  
  607.           define_dollar_label (temp);
  608.           colon (dollar_label_name (temp, 0));
  609.           continue;
  610.         }
  611. #endif /* LOCAL_LABELS_DOLLAR */
  612.  
  613. #ifdef LOCAL_LABELS_FB
  614.           if (*input_line_pointer++ == ':')
  615.         {
  616.           fb_label_instance_inc (temp);
  617.           colon (fb_label_name (temp, 0));
  618.           continue;
  619.         }
  620. #endif /* LOCAL_LABELS_FB */
  621.  
  622.           input_line_pointer = backup;
  623.         }            /* local label  ("4:") */
  624. #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
  625.  
  626.       if (c && strchr (line_comment_chars, c))
  627.         {            /* Its a comment.  Better say APP or NO_APP */
  628.           char *ends;
  629.           char *new_buf;
  630.           char *new_tmp;
  631.           unsigned int new_length;
  632.           char *tmp_buf = 0;
  633.           extern char *scrub_string, *scrub_last_string;
  634.  
  635.           bump_line_counters ();
  636.           s = input_line_pointer;
  637.           if (strncmp (s, "APP\n", 4))
  638.         continue;    /* We ignore it */
  639.           s += 4;
  640.  
  641.           ends = strstr (s, "#NO_APP\n");
  642.  
  643.           if (!ends)
  644.         {
  645.           unsigned int tmp_len;
  646.           unsigned int num;
  647.  
  648.           /* The end of the #APP wasn't in this buffer.  We
  649.              keep reading in buffers until we find the #NO_APP
  650.              that goes with this #APP  There is one.  The specs
  651.              guarentee it. . . */
  652.           tmp_len = buffer_limit - s;
  653.           tmp_buf = xmalloc (tmp_len + 1);
  654.           memcpy (tmp_buf, s, tmp_len);
  655.           do
  656.             {
  657.               new_tmp = input_scrub_next_buffer (&buffer);
  658.               if (!new_tmp)
  659.             break;
  660.               else
  661.             buffer_limit = new_tmp;
  662.               input_line_pointer = buffer;
  663.               ends = strstr (buffer, "#NO_APP\n");
  664.               if (ends)
  665.             num = ends - buffer;
  666.               else
  667.             num = buffer_limit - buffer;
  668.  
  669.               tmp_buf = xrealloc (tmp_buf, tmp_len + num);
  670.               memcpy (tmp_buf + tmp_len, buffer, num);
  671.               tmp_len += num;
  672.             }
  673.           while (!ends);
  674.  
  675.           input_line_pointer = ends ? ends + 8 : NULL;
  676.  
  677.           s = tmp_buf;
  678.           ends = s + tmp_len;
  679.  
  680.         }
  681.           else
  682.         {
  683.           input_line_pointer = ends + 8;
  684.         }
  685.           new_buf = xmalloc (100);
  686.           new_length = 100;
  687.           new_tmp = new_buf;
  688.  
  689.           scrub_string = s;
  690.           scrub_last_string = ends;
  691.           for (;;)
  692.         {
  693.           int ch;
  694.  
  695.           ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
  696.           if (ch == EOF)
  697.             break;
  698.           *new_tmp++ = ch;
  699.           if (new_tmp == new_buf + new_length)
  700.             {
  701.               new_buf = xrealloc (new_buf, new_length + 100);
  702.               new_tmp = new_buf + new_length;
  703.               new_length += 100;
  704.             }
  705.         }
  706.  
  707.           if (tmp_buf)
  708.         free (tmp_buf);
  709.           old_buffer = buffer;
  710.           old_input = input_line_pointer;
  711.           old_limit = buffer_limit;
  712.           buffer = new_buf;
  713.           input_line_pointer = new_buf;
  714.           buffer_limit = new_tmp;
  715.           continue;
  716.         }
  717.  
  718.       HANDLE_CONDITIONAL_ASSEMBLY ();
  719.  
  720.       /* as_warn("Junk character %d.",c);  Now done by ignore_rest */
  721.       input_line_pointer--;    /* Report unknown char as ignored. */
  722.       ignore_rest_of_line ();
  723.     }            /* while (input_line_pointer<buffer_limit) */
  724.       if (old_buffer)
  725.     {
  726.       bump_line_counters ();
  727.       if (old_input != 0)
  728.         {
  729.           buffer = old_buffer;
  730.           input_line_pointer = old_input;
  731.           buffer_limit = old_limit;
  732.           old_buffer = 0;
  733.           goto contin;
  734.         }
  735.     }
  736.     }                /* while (more buffers to scan) */
  737.   input_scrub_close ();        /* Close the input file */
  738.  
  739. }
  740.  
  741. void 
  742. s_abort (ignore)
  743.      int ignore;
  744. {
  745.   as_fatal (".abort detected.  Abandoning ship.");
  746. }
  747.  
  748. /* Guts of .align directive.  */
  749. static void 
  750. do_align (n, fill)
  751.      int n;
  752.      char *fill;
  753. {
  754. #ifdef md_do_align
  755.   md_do_align (n, fill, just_record_alignment);
  756. #endif
  757.   if (!fill)
  758.     {
  759.       /* @@ Fix this right for BFD!  */
  760.       static char zero;
  761.       static char nop_opcode = NOP_OPCODE;
  762.  
  763.       if (now_seg != data_section && now_seg != bss_section)
  764.     {
  765.       fill = &nop_opcode;
  766.     }
  767.       else
  768.     {
  769.       fill = &zero;
  770.     }
  771.     }
  772.   /* Only make a frag if we HAVE to. . . */
  773.   if (n && !need_pass_2)
  774.     frag_align (n, *fill);
  775.  
  776. #ifdef md_do_align
  777.  just_record_alignment:
  778. #endif
  779.  
  780.   record_alignment (now_seg, n);
  781. }
  782.  
  783. /* For machines where ".align 4" means align to a 4 byte boundary. */
  784. void 
  785. s_align_bytes (arg)
  786.      int arg;
  787. {
  788.   register unsigned int temp;
  789.   char temp_fill;
  790.   unsigned int i = 0;
  791.   unsigned long max_alignment = 1 << 15;
  792.  
  793.   if (is_end_of_line[(unsigned char) *input_line_pointer])
  794.     temp = arg;            /* Default value from pseudo-op table */
  795.   else
  796.     temp = get_absolute_expression ();
  797.  
  798.   if (temp > max_alignment)
  799.     {
  800.       as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
  801.     }
  802.  
  803.   /* For the sparc, `.align (1<<n)' actually means `.align n' so we
  804.      have to convert it.  */
  805.   if (temp != 0)
  806.     {
  807.       for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
  808.     ;
  809.     }
  810.   if (temp != 1)
  811.     as_bad ("Alignment not a power of 2");
  812.  
  813.   temp = i;
  814.   if (*input_line_pointer == ',')
  815.     {
  816.       input_line_pointer++;
  817.       temp_fill = get_absolute_expression ();
  818.       do_align (temp, &temp_fill);
  819.     }
  820.   else
  821.     do_align (temp, (char *) 0);
  822.  
  823.   demand_empty_rest_of_line ();
  824. }
  825.  
  826. /* For machines where ".align 4" means align to 2**4 boundary. */
  827. void 
  828. s_align_ptwo (ignore)
  829.      int ignore;
  830. {
  831.   register int temp;
  832.   char temp_fill;
  833.   long max_alignment = 15;
  834.  
  835.   temp = get_absolute_expression ();
  836.   if (temp > max_alignment)
  837.     as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
  838.   else if (temp < 0)
  839.     {
  840.       as_bad ("Alignment negative. 0 assumed.");
  841.       temp = 0;
  842.     }
  843.   if (*input_line_pointer == ',')
  844.     {
  845.       input_line_pointer++;
  846.       temp_fill = get_absolute_expression ();
  847.       do_align (temp, &temp_fill);
  848.     }
  849.   else
  850.     do_align (temp, (char *) 0);
  851.  
  852.   demand_empty_rest_of_line ();
  853. }
  854.  
  855. void 
  856. s_comm (ignore)
  857.      int ignore;
  858. {
  859.   register char *name;
  860.   register char c;
  861.   register char *p;
  862.   offsetT temp;
  863.   register symbolS *symbolP;
  864.  
  865.   name = input_line_pointer;
  866.   c = get_symbol_end ();
  867.   /* just after name is now '\0' */
  868.   p = input_line_pointer;
  869.   *p = c;
  870.   SKIP_WHITESPACE ();
  871.   if (*input_line_pointer != ',')
  872.     {
  873.       as_bad ("Expected comma after symbol-name: rest of line ignored.");
  874.       ignore_rest_of_line ();
  875.       return;
  876.     }
  877.   input_line_pointer++;        /* skip ',' */
  878.   if ((temp = get_absolute_expression ()) < 0)
  879.     {
  880.       as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
  881.       ignore_rest_of_line ();
  882.       return;
  883.     }
  884.   *p = 0;
  885.   symbolP = symbol_find_or_make (name);
  886.   *p = c;
  887.   if (S_IS_DEFINED (symbolP))
  888.     {
  889.       as_bad ("Ignoring attempt to re-define symbol `%s'.",
  890.           S_GET_NAME (symbolP));
  891.       ignore_rest_of_line ();
  892.       return;
  893.     }
  894.   if (S_GET_VALUE (symbolP))
  895.     {
  896.       if (S_GET_VALUE (symbolP) != (valueT) temp)
  897.     as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
  898.         S_GET_NAME (symbolP),
  899.         (long) S_GET_VALUE (symbolP),
  900.         (long) temp);
  901.     }
  902.   else
  903.     {
  904.       S_SET_VALUE (symbolP, (valueT) temp);
  905.       S_SET_EXTERNAL (symbolP);
  906.     }
  907. #ifdef OBJ_VMS
  908.   {
  909.     extern int flag_one;
  910.     if ( (!temp) || !flag_one)
  911.       S_GET_OTHER(symbolP) = const_flag;
  912.   }
  913. #endif /* not OBJ_VMS */
  914.   know (symbolP->sy_frag == &zero_address_frag);
  915.   demand_empty_rest_of_line ();
  916. }                /* s_comm() */
  917.  
  918. void
  919. s_data (ignore)
  920.      int ignore;
  921. {
  922.   segT section;
  923.   register int temp;
  924.  
  925.   temp = get_absolute_expression ();
  926.   if (flag_readonly_data_in_text)
  927.     {
  928.       section = text_section;
  929.       temp += 1000;
  930.     }
  931.   else
  932.     section = data_section;
  933.  
  934.   subseg_set (section, (subsegT) temp);
  935.  
  936. #ifdef OBJ_VMS
  937.   const_flag = 0;
  938. #endif
  939.   demand_empty_rest_of_line ();
  940. }
  941.  
  942. /* Handle the .appfile pseudo-op.  This is automatically generated by
  943.    do_scrub_next_char when a preprocessor # line comment is seen with
  944.    a file name.  This default definition may be overridden by the
  945.    object or CPU specific pseudo-ops.  This function is also the
  946.    default definition for .file; the APPFILE argument is 1 for
  947.    .appfile, 0 for .file.  */
  948.  
  949. void 
  950. s_app_file (appfile)
  951.      int appfile;
  952. {
  953.   register char *s;
  954.   int length;
  955.  
  956.   /* Some assemblers tolerate immediately following '"' */
  957.   if ((s = demand_copy_string (&length)) != 0)
  958.     {
  959.       /* If this is a fake .appfile, a fake newline was inserted into
  960.      the buffer.  Passing -2 to new_logical_line tells it to
  961.      account for it.  */
  962.       new_logical_line (s, appfile ? -2 : -1);
  963.       demand_empty_rest_of_line ();
  964. #ifdef LISTING
  965.       if (listing)
  966.     listing_source_file (s);
  967. #endif
  968.     }
  969. #ifdef OBJ_COFF
  970.   c_dot_file_symbol (s);
  971. #endif /* OBJ_COFF */
  972. #ifdef OBJ_ELF
  973.   elf_file_symbol (s);
  974. #endif
  975. }
  976.  
  977. /* Handle the .appline pseudo-op.  This is automatically generated by
  978.    do_scrub_next_char when a preprocessor # line comment is seen.
  979.    This default definition may be overridden by the object or CPU
  980.    specific pseudo-ops.  */
  981.  
  982. void
  983. s_app_line (ignore)
  984.      int ignore;
  985. {
  986.   int l;
  987.  
  988.   /* The given number is that of the next line.  */
  989.   l = get_absolute_expression () - 1;
  990.   new_logical_line ((char *) NULL, l);
  991. #ifdef LISTING
  992.   if (listing)
  993.     listing_source_line (l);
  994. #endif
  995.   demand_empty_rest_of_line ();
  996. }
  997.  
  998. void 
  999. s_fill (ignore)
  1000.      int ignore;
  1001. {
  1002.   long temp_repeat = 0;
  1003.   long temp_size = 1;
  1004.   register long temp_fill = 0;
  1005.   char *p;
  1006.  
  1007.  
  1008.   temp_repeat = get_absolute_expression ();
  1009.   if (*input_line_pointer == ',')
  1010.     {
  1011.       input_line_pointer++;
  1012.       temp_size = get_absolute_expression ();
  1013.       if (*input_line_pointer == ',')
  1014.     {
  1015.       input_line_pointer++;
  1016.       temp_fill = get_absolute_expression ();
  1017.     }
  1018.     }
  1019.   /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
  1020. #define BSD_FILL_SIZE_CROCK_8 (8)
  1021.   if (temp_size > BSD_FILL_SIZE_CROCK_8)
  1022.     {
  1023.       as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
  1024.       temp_size = BSD_FILL_SIZE_CROCK_8;
  1025.     }
  1026.   if (temp_size < 0)
  1027.     {
  1028.       as_warn ("Size negative: .fill ignored.");
  1029.       temp_size = 0;
  1030.     }
  1031.   else if (temp_repeat <= 0)
  1032.     {
  1033.       as_warn ("Repeat < 0, .fill ignored");
  1034.       temp_size = 0;
  1035.     }
  1036.  
  1037.   if (temp_size && !need_pass_2)
  1038.     {
  1039.       p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
  1040.       memset (p, 0, (unsigned int) temp_size);
  1041.       /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
  1042.        * flavoured AS.  The following bizzare behaviour is to be
  1043.        * compatible with above.  I guess they tried to take up to 8
  1044.        * bytes from a 4-byte expression and they forgot to sign
  1045.        * extend. Un*x Sux. */
  1046. #define BSD_FILL_SIZE_CROCK_4 (4)
  1047.       md_number_to_chars (p, (valueT) temp_fill,
  1048.               (temp_size > BSD_FILL_SIZE_CROCK_4
  1049.                ? BSD_FILL_SIZE_CROCK_4
  1050.                : (int) temp_size));
  1051.       /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
  1052.        * but emits no error message because it seems a legal thing to do.
  1053.        * It is a degenerate case of .fill but could be emitted by a compiler.
  1054.        */
  1055.     }
  1056.   demand_empty_rest_of_line ();
  1057. }
  1058.  
  1059. void 
  1060. s_globl (ignore)
  1061.      int ignore;
  1062. {
  1063.   char *name;
  1064.   int c;
  1065.   symbolS *symbolP;
  1066.  
  1067.   do
  1068.     {
  1069.       name = input_line_pointer;
  1070.       c = get_symbol_end ();
  1071.       symbolP = symbol_find_or_make (name);
  1072.       *input_line_pointer = c;
  1073.       SKIP_WHITESPACE ();
  1074.       S_SET_EXTERNAL (symbolP);
  1075.       if (c == ',')
  1076.     {
  1077.       input_line_pointer++;
  1078.       SKIP_WHITESPACE ();
  1079.       if (*input_line_pointer == '\n')
  1080.         c = '\n';
  1081.     }
  1082.     }
  1083.   while (c == ',');
  1084.   demand_empty_rest_of_line ();
  1085. }
  1086.  
  1087. void 
  1088. s_lcomm (needs_align)
  1089.      /* 1 if this was a ".bss" directive, which may require a 3rd argument
  1090.     (alignment); 0 if it was an ".lcomm" (2 args only)  */
  1091.      int needs_align;
  1092. {
  1093.   register char *name;
  1094.   register char c;
  1095.   register char *p;
  1096.   register int temp;
  1097.   register symbolS *symbolP;
  1098.   segT current_seg = now_seg;
  1099.   subsegT current_subseg = now_subseg;
  1100.   const int max_alignment = 15;
  1101.   int align = 0;
  1102.   segT bss_seg = bss_section;
  1103.  
  1104.   name = input_line_pointer;
  1105.   c = get_symbol_end ();
  1106.   p = input_line_pointer;
  1107.   *p = c;
  1108.   SKIP_WHITESPACE ();
  1109.  
  1110.   /* Accept an optional comma after the name.  The comma used to be
  1111.      required, but Irix 5 cc does not generate it.  */
  1112.   if (*input_line_pointer == ',')
  1113.     {
  1114.       ++input_line_pointer;
  1115.       SKIP_WHITESPACE ();
  1116.     }
  1117.  
  1118.   if (*input_line_pointer == '\n')
  1119.     {
  1120.       as_bad ("Missing size expression");
  1121.       return;
  1122.     }
  1123.  
  1124.   if ((temp = get_absolute_expression ()) < 0)
  1125.     {
  1126.       as_warn ("BSS length (%d.) <0! Ignored.", temp);
  1127.       ignore_rest_of_line ();
  1128.       return;
  1129.     }
  1130.  
  1131. #if defined (TC_MIPS) || defined (TC_ALPHA)
  1132. #if defined (OBJ_ECOFF) || defined (OBJ_ELF)
  1133.   /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
  1134.   if (temp <= bfd_get_gp_size (stdoutput))
  1135.     {
  1136.       bss_seg = subseg_new (".sbss", 1);
  1137.       seg_info (bss_seg)->bss = 1;
  1138.     }
  1139. #endif
  1140. #endif
  1141.    if (!needs_align)
  1142.      {
  1143.        /* FIXME. This needs to be machine independent. */
  1144.        if (temp >= 8)
  1145.      align = 3;
  1146.        else if (temp >= 4)
  1147.      align = 2;
  1148.        else if (temp >= 2)
  1149.      align = 1;
  1150.        else
  1151.      align = temp;
  1152.  
  1153.        record_alignment(bss_seg, align);
  1154.      }
  1155.  
  1156.   if (needs_align)
  1157.     {
  1158.       align = 0;
  1159.       SKIP_WHITESPACE ();
  1160.       if (*input_line_pointer != ',')
  1161.     {
  1162.       as_bad ("Expected comma after size");
  1163.       ignore_rest_of_line ();
  1164.       return;
  1165.     }
  1166.       input_line_pointer++;
  1167.       SKIP_WHITESPACE ();
  1168.       if (*input_line_pointer == '\n')
  1169.     {
  1170.       as_bad ("Missing alignment");
  1171.       return;
  1172.     }
  1173.       align = get_absolute_expression ();
  1174.       if (align > max_alignment)
  1175.     {
  1176.       align = max_alignment;
  1177.       as_warn ("Alignment too large: %d. assumed.", align);
  1178.     }
  1179.       else if (align < 0)
  1180.     {
  1181.       align = 0;
  1182.       as_warn ("Alignment negative. 0 assumed.");
  1183.     }
  1184.       record_alignment (bss_seg, align);
  1185.     }                /* if needs align */
  1186.   else
  1187.     {
  1188.       /* Assume some objects may require alignment on some systems.  */
  1189. #ifdef TC_ALPHA
  1190.       if (temp > 1)
  1191.     {
  1192.       align = ffs (temp) - 1;
  1193.       if (temp % (1 << align))
  1194.         abort ();
  1195.     }
  1196. #endif
  1197.     }
  1198.  
  1199.   *p = 0;
  1200.   symbolP = symbol_find_or_make (name);
  1201.   *p = c;
  1202.  
  1203.   if (
  1204. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1205.        S_GET_OTHER (symbolP) == 0 &&
  1206.        S_GET_DESC (symbolP) == 0 &&
  1207. #endif /* OBJ_AOUT or OBJ_BOUT */
  1208.        (S_GET_SEGMENT (symbolP) == bss_seg
  1209.     || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
  1210.     {
  1211.       char *pfrag;
  1212.  
  1213.       subseg_set (bss_seg, 1);
  1214.  
  1215.       if (align)
  1216.     frag_align (align, 0);
  1217.                     /* detach from old frag    */
  1218.       if (S_GET_SEGMENT (symbolP) == bss_seg)
  1219.     symbolP->sy_frag->fr_symbol = NULL;
  1220.  
  1221.       symbolP->sy_frag = frag_now;
  1222.       pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
  1223.             temp, (char *)0);
  1224.       *pfrag = 0;
  1225.  
  1226.       S_SET_SEGMENT (symbolP, bss_seg);
  1227.  
  1228. #ifdef OBJ_COFF
  1229.       /* The symbol may already have been created with a preceding
  1230.          ".globl" directive -- be careful not to step on storage class
  1231.          in that case.  Otherwise, set it to static. */
  1232.       if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
  1233.     {
  1234.       S_SET_STORAGE_CLASS (symbolP, C_STAT);
  1235.     }
  1236. #endif /* OBJ_COFF */
  1237.     }
  1238.   else
  1239.     as_bad ("Ignoring attempt to re-define symbol `%s'.",
  1240.         S_GET_NAME (symbolP));
  1241.  
  1242.   subseg_set (current_seg, current_subseg);
  1243.  
  1244.   demand_empty_rest_of_line ();
  1245. }                /* s_lcomm() */
  1246.  
  1247. void 
  1248. s_lsym (ignore)
  1249.      int ignore;
  1250. {
  1251.   register char *name;
  1252.   register char c;
  1253.   register char *p;
  1254.   expressionS exp;
  1255.   register symbolS *symbolP;
  1256.  
  1257.   /* we permit ANY defined expression: BSD4.2 demands constants */
  1258.   name = input_line_pointer;
  1259.   c = get_symbol_end ();
  1260.   p = input_line_pointer;
  1261.   *p = c;
  1262.   SKIP_WHITESPACE ();
  1263.   if (*input_line_pointer != ',')
  1264.     {
  1265.       *p = 0;
  1266.       as_bad ("Expected comma after name \"%s\"", name);
  1267.       *p = c;
  1268.       ignore_rest_of_line ();
  1269.       return;
  1270.     }
  1271.   input_line_pointer++;
  1272.   expression (&exp);
  1273.   if (exp.X_op != O_constant
  1274.       && exp.X_op != O_register)
  1275.     {
  1276.       as_bad ("bad expression");
  1277.       ignore_rest_of_line ();
  1278.       return;
  1279.     }
  1280.   *p = 0;
  1281.   symbolP = symbol_find_or_make (name);
  1282.  
  1283.   /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
  1284.      symbolP->sy_desc == 0) out of this test because coff doesn't have
  1285.      those fields, and I can't see when they'd ever be tripped.  I
  1286.      don't think I understand why they were here so I may have
  1287.      introduced a bug. As recently as 1.37 didn't have this test
  1288.      anyway.  xoxorich. */
  1289.  
  1290.   if (S_GET_SEGMENT (symbolP) == undefined_section
  1291.       && S_GET_VALUE (symbolP) == 0)
  1292.     {
  1293.       /* The name might be an undefined .global symbol; be sure to
  1294.      keep the "external" bit. */
  1295.       S_SET_SEGMENT (symbolP,
  1296.              (exp.X_op == O_constant
  1297.               ? absolute_section
  1298.               : reg_section));
  1299.       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
  1300.     }
  1301.   else
  1302.     {
  1303.       as_bad ("Symbol %s already defined", name);
  1304.     }
  1305.   *p = c;
  1306.   demand_empty_rest_of_line ();
  1307. }                /* s_lsym() */
  1308.  
  1309. void 
  1310. s_org (ignore)
  1311.      int ignore;
  1312. {
  1313.   register segT segment;
  1314.   expressionS exp;
  1315.   register long temp_fill;
  1316.   register char *p;
  1317.   /* Don't believe the documentation of BSD 4.2 AS.  There is no such
  1318.      thing as a sub-segment-relative origin.  Any absolute origin is
  1319.      given a warning, then assumed to be segment-relative.  Any
  1320.      segmented origin expression ("foo+42") had better be in the right
  1321.      segment or the .org is ignored.
  1322.  
  1323.      BSD 4.2 AS warns if you try to .org backwards. We cannot because
  1324.      we never know sub-segment sizes when we are reading code.  BSD
  1325.      will crash trying to emit negative numbers of filler bytes in
  1326.      certain .orgs. We don't crash, but see as-write for that code.
  1327.  
  1328.      Don't make frag if need_pass_2==1.  */
  1329.   segment = get_known_segmented_expression (&exp);
  1330.   if (*input_line_pointer == ',')
  1331.     {
  1332.       input_line_pointer++;
  1333.       temp_fill = get_absolute_expression ();
  1334.     }
  1335.   else
  1336.     temp_fill = 0;
  1337.   if (!need_pass_2)
  1338.     {
  1339.       if (segment != now_seg && segment != absolute_section)
  1340.     as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
  1341.         segment_name (segment), segment_name (now_seg));
  1342.       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
  1343.             exp.X_add_number, (char *) 0);
  1344.       *p = temp_fill;
  1345.     }                /* if (ok to make frag) */
  1346.   demand_empty_rest_of_line ();
  1347. }                /* s_org() */
  1348.  
  1349. void 
  1350. s_set (ignore)
  1351.      int ignore;
  1352. {
  1353.   register char *name;
  1354.   register char delim;
  1355.   register char *end_name;
  1356.   register symbolS *symbolP;
  1357.  
  1358.   /*
  1359.    * Especial apologies for the random logic:
  1360.    * this just grew, and could be parsed much more simply!
  1361.    * Dean in haste.
  1362.    */
  1363.   name = input_line_pointer;
  1364.   delim = get_symbol_end ();
  1365.   end_name = input_line_pointer;
  1366.   *end_name = delim;
  1367.   SKIP_WHITESPACE ();
  1368.  
  1369.   if (*input_line_pointer != ',')
  1370.     {
  1371.       *end_name = 0;
  1372.       as_bad ("Expected comma after name \"%s\"", name);
  1373.       *end_name = delim;
  1374.       ignore_rest_of_line ();
  1375.       return;
  1376.     }
  1377.  
  1378.   input_line_pointer++;
  1379.   *end_name = 0;
  1380.  
  1381.   if (name[0] == '.' && name[1] == '\0')
  1382.     {
  1383.       /* Turn '. = mumble' into a .org mumble */
  1384.       register segT segment;
  1385.       expressionS exp;
  1386.       register char *ptr;
  1387.  
  1388.       segment = get_known_segmented_expression (&exp);
  1389.  
  1390.       if (!need_pass_2)
  1391.     {
  1392.       if (segment != now_seg && segment != absolute_section)
  1393.         as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
  1394.             segment_name (segment),
  1395.             segment_name (now_seg));
  1396.       ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
  1397.               exp.X_add_number, (char *) 0);
  1398.       *ptr = 0;
  1399.     }            /* if (ok to make frag) */
  1400.  
  1401.       *end_name = delim;
  1402.       return;
  1403.     }
  1404.  
  1405.   if ((symbolP = symbol_find (name)) == NULL
  1406.       && (symbolP = md_undefined_symbol (name)) == NULL)
  1407.     {
  1408.       symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
  1409. #ifdef OBJ_COFF
  1410.       /* "set" symbols are local unless otherwise specified. */
  1411.       SF_SET_LOCAL (symbolP);
  1412. #endif /* OBJ_COFF */
  1413.  
  1414.     }                /* make a new symbol */
  1415.  
  1416.   symbol_table_insert (symbolP);
  1417.  
  1418.   *end_name = delim;
  1419.   pseudo_set (symbolP);
  1420.   demand_empty_rest_of_line ();
  1421. }                /* s_set() */
  1422.  
  1423. void 
  1424. s_space (mult)
  1425.      int mult;
  1426. {
  1427.   long temp_repeat;
  1428.   register long temp_fill;
  1429.   register char *p;
  1430.  
  1431.   /* Just like .fill, but temp_size = 1 */
  1432.   if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
  1433.     {
  1434.       temp_fill = get_absolute_expression ();
  1435.     }
  1436.   else
  1437.     {
  1438.       input_line_pointer--;    /* Backup over what was not a ','. */
  1439.       temp_fill = 0;
  1440.     }
  1441.   if (mult)
  1442.     {
  1443.       temp_repeat *= mult;
  1444.     }
  1445.   if (temp_repeat <= 0)
  1446.     {
  1447.       as_warn ("Repeat < 0, .space ignored");
  1448.       ignore_rest_of_line ();
  1449.       return;
  1450.     }
  1451.   if (!need_pass_2)
  1452.     {
  1453.       p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
  1454.             temp_repeat, (char *) 0);
  1455.       *p = temp_fill;
  1456.     }
  1457.   demand_empty_rest_of_line ();
  1458. }                /* s_space() */
  1459.  
  1460. void
  1461. s_text (ignore)
  1462.      int ignore;
  1463. {
  1464.   register int temp;
  1465.  
  1466.   temp = get_absolute_expression ();
  1467.   subseg_set (text_section, (subsegT) temp);
  1468.   demand_empty_rest_of_line ();
  1469. #ifdef OBJ_VMS
  1470.   const_flag &= ~IN_DEFAULT_SECTION;
  1471. #endif
  1472. }                /* s_text() */
  1473.  
  1474.  
  1475. void 
  1476. demand_empty_rest_of_line ()
  1477. {
  1478.   SKIP_WHITESPACE ();
  1479.   if (is_end_of_line[(unsigned char) *input_line_pointer])
  1480.     {
  1481.       input_line_pointer++;
  1482.     }
  1483.   else
  1484.     {
  1485.       ignore_rest_of_line ();
  1486.     }
  1487.   /* Return having already swallowed end-of-line. */
  1488. }                /* Return pointing just after end-of-line. */
  1489.  
  1490. void
  1491. ignore_rest_of_line ()        /* For suspect lines: gives warning. */
  1492. {
  1493.   if (!is_end_of_line[(unsigned char) *input_line_pointer])
  1494.     {
  1495.       if (isprint (*input_line_pointer))
  1496.     as_bad ("Rest of line ignored. First ignored character is `%c'.",
  1497.         *input_line_pointer);
  1498.       else
  1499.     as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
  1500.         *input_line_pointer);
  1501.       while (input_line_pointer < buffer_limit
  1502.          && !is_end_of_line[(unsigned char) *input_line_pointer])
  1503.     {
  1504.       input_line_pointer++;
  1505.     }
  1506.     }
  1507.   input_line_pointer++;        /* Return pointing just after end-of-line. */
  1508.   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
  1509. }
  1510.  
  1511. /*
  1512.  *            pseudo_set()
  1513.  *
  1514.  * In:    Pointer to a symbol.
  1515.  *    Input_line_pointer->expression.
  1516.  *
  1517.  * Out:    Input_line_pointer->just after any whitespace after expression.
  1518.  *    Tried to set symbol to value of expression.
  1519.  *    Will change symbols type, value, and frag;
  1520.  */
  1521. void
  1522. pseudo_set (symbolP)
  1523.      symbolS *symbolP;
  1524. {
  1525.   expressionS exp;
  1526. #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
  1527.   int ext;
  1528. #endif /* OBJ_AOUT or OBJ_BOUT */
  1529.  
  1530.   know (symbolP);        /* NULL pointer is logic error. */
  1531. #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
  1532.   ext = S_IS_EXTERNAL (symbolP);
  1533. #endif /* OBJ_AOUT or OBJ_BOUT */
  1534.  
  1535.   (void) expression (&exp);
  1536.  
  1537.   if (exp.X_op == O_illegal)
  1538.     as_bad ("illegal expression; zero assumed");
  1539.   else if (exp.X_op == O_absent)
  1540.     as_bad ("missing expression; zero assumed");
  1541.   else if (exp.X_op == O_big)
  1542.     as_bad ("%s number invalid; zero assumed",
  1543.         exp.X_add_number > 0 ? "bignum" : "floating point");
  1544.   else if (exp.X_op == O_subtract
  1545.        && (S_GET_SEGMENT (exp.X_add_symbol)
  1546.            == S_GET_SEGMENT (exp.X_op_symbol))
  1547.        && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
  1548.        && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
  1549.     {
  1550.       exp.X_op = O_constant;
  1551.       exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
  1552.               - S_GET_VALUE (exp.X_op_symbol));
  1553.     }
  1554.  
  1555.   switch (exp.X_op)
  1556.     {
  1557.     case O_illegal:
  1558.     case O_absent:
  1559.     case O_big:
  1560.       exp.X_add_number = 0;
  1561.       /* Fall through.  */
  1562.     case O_constant:
  1563.       S_SET_SEGMENT (symbolP, absolute_section);
  1564. #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
  1565.       if (ext)
  1566.     S_SET_EXTERNAL (symbolP);
  1567.       else
  1568.     S_CLEAR_EXTERNAL (symbolP);
  1569. #endif /* OBJ_AOUT or OBJ_BOUT */
  1570.       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
  1571.       symbolP->sy_frag = &zero_address_frag;
  1572.       break;
  1573.  
  1574.     case O_register:
  1575.       S_SET_SEGMENT (symbolP, reg_section);
  1576.       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
  1577.       symbolP->sy_frag = &zero_address_frag;
  1578.       break;
  1579.  
  1580.     case O_symbol:
  1581.       if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
  1582.       || exp.X_add_number != 0)
  1583.     symbolP->sy_value = exp;
  1584.       else
  1585.     {
  1586.       symbolS *s = exp.X_add_symbol;
  1587.  
  1588.       S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
  1589. #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
  1590.       if (ext)
  1591.         S_SET_EXTERNAL (symbolP);
  1592.       else
  1593.         S_CLEAR_EXTERNAL (symbolP);
  1594. #endif /* OBJ_AOUT or OBJ_BOUT */
  1595.       S_SET_VALUE (symbolP,
  1596.                exp.X_add_number + S_GET_VALUE (s));
  1597.       symbolP->sy_frag = s->sy_frag;
  1598.       copy_symbol_attributes (symbolP, s);
  1599.     }
  1600.       break;
  1601.  
  1602.     default:
  1603.       /* The value is some complex expression.
  1604.      FIXME: Should we set the segment to anything?  */
  1605.       symbolP->sy_value = exp;
  1606.       break;
  1607.     }
  1608. }
  1609.  
  1610. /*
  1611.  *            cons()
  1612.  *
  1613.  * CONStruct more frag of .bytes, or .words etc.
  1614.  * Should need_pass_2 be 1 then emit no frag(s).
  1615.  * This understands EXPRESSIONS.
  1616.  *
  1617.  * Bug (?)
  1618.  *
  1619.  * This has a split personality. We use expression() to read the
  1620.  * value. We can detect if the value won't fit in a byte or word.
  1621.  * But we can't detect if expression() discarded significant digits
  1622.  * in the case of a long. Not worth the crocks required to fix it.
  1623.  */
  1624.  
  1625. /* Select a parser for cons expressions.  */
  1626.  
  1627. /* Some targets need to parse the expression in various fancy ways.
  1628.    You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
  1629.    (for example, the HPPA does this).  Otherwise, you can define
  1630.    BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
  1631.    REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
  1632.    are defined, which is the normal case, then only simple expressions
  1633.    are permitted.  */
  1634.  
  1635. #ifndef TC_PARSE_CONS_EXPRESSION
  1636. #ifdef BITFIELD_CONS_EXPRESSIONS
  1637. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
  1638. static void 
  1639. parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
  1640. #endif
  1641. #ifdef MRI
  1642. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
  1643. static void
  1644. parse_mri_cons PARAMS ((expressionS *exp));
  1645. #endif
  1646. #ifdef REPEAT_CONS_EXPRESSIONS
  1647. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
  1648. static void
  1649. parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
  1650. #endif
  1651.  
  1652. /* If we haven't gotten one yet, just call expression.  */
  1653. #ifndef TC_PARSE_CONS_EXPRESSION
  1654. #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
  1655. #endif
  1656. #endif
  1657.  
  1658. /* worker to do .byte etc statements */
  1659. /* clobbers input_line_pointer, checks */
  1660. /* end-of-line. */
  1661. void 
  1662. cons (nbytes)
  1663.      register int nbytes;    /* 1=.byte, 2=.word, 4=.long */
  1664. {
  1665.   expressionS exp;
  1666.  
  1667.   if (is_it_end_of_statement ())
  1668.     {
  1669.       demand_empty_rest_of_line ();
  1670.       return;
  1671.     }
  1672.  
  1673.   do
  1674.     {
  1675.       TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
  1676.       emit_expr (&exp, (unsigned int) nbytes);
  1677.     }
  1678.   while (*input_line_pointer++ == ',');
  1679.  
  1680.   input_line_pointer--;        /* Put terminator back into stream. */
  1681.   demand_empty_rest_of_line ();
  1682. }
  1683.  
  1684. /* Put the contents of expression EXP into the object file using
  1685.    NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
  1686.  
  1687. void
  1688. emit_expr (exp, nbytes)
  1689.      expressionS *exp;
  1690.      unsigned int nbytes;
  1691. {
  1692.   operatorT op;
  1693.   register char *p;
  1694.   valueT extra_digit = 0;
  1695.  
  1696.   /* Don't do anything if we are going to make another pass.  */
  1697.   if (need_pass_2)
  1698.     return;
  1699.  
  1700.   op = exp->X_op;
  1701.  
  1702.   /* Handle a negative bignum.  */
  1703.   if (op == O_uminus
  1704.       && exp->X_add_number == 0
  1705.       && exp->X_add_symbol->sy_value.X_op == O_big
  1706.       && exp->X_add_symbol->sy_value.X_add_number > 0)
  1707.     {
  1708.       int i;
  1709.       unsigned long carry;
  1710.  
  1711.       exp = &exp->X_add_symbol->sy_value;
  1712.  
  1713.       /* Negate the bignum: one's complement each digit and add 1.  */
  1714.       carry = 1;
  1715.       for (i = 0; i < exp->X_add_number; i++)
  1716.     {
  1717.       unsigned long next;
  1718.  
  1719.       next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
  1720.            & LITTLENUM_MASK)
  1721.           + carry);
  1722.       generic_bignum[i] = next & LITTLENUM_MASK;
  1723.       carry = next >> LITTLENUM_NUMBER_OF_BITS;
  1724.     }
  1725.  
  1726.       /* We can ignore any carry out, because it will be handled by
  1727.      extra_digit if it is needed.  */
  1728.  
  1729.       extra_digit = (valueT) -1;
  1730.       op = O_big;
  1731.     }
  1732.  
  1733.   if (op == O_absent || op == O_illegal)
  1734.     {
  1735.       as_warn ("zero assumed for missing expression");
  1736.       exp->X_add_number = 0;
  1737.       op = O_constant;
  1738.     }
  1739.   else if (op == O_big && exp->X_add_number <= 0)
  1740.     {
  1741.       as_bad ("floating point number invalid; zero assumed");
  1742.       exp->X_add_number = 0;
  1743.       op = O_constant;
  1744.     }
  1745.   else if (op == O_register)
  1746.     {
  1747.       as_warn ("register value used as expression");
  1748.       op = O_constant;
  1749.     }
  1750.  
  1751.   p = frag_more ((int) nbytes);
  1752.  
  1753. #ifndef WORKING_DOT_WORD
  1754.   /* If we have the difference of two symbols in a word, save it on
  1755.      the broken_words list.  See the code in write.c.  */
  1756.   if (op == O_subtract && nbytes == 2)
  1757.     {
  1758.       struct broken_word *x;
  1759.  
  1760.       x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
  1761.       x->next_broken_word = broken_words;
  1762.       broken_words = x;
  1763.       x->frag = frag_now;
  1764.       x->word_goes_here = p;
  1765.       x->dispfrag = 0;
  1766.       x->add = exp->X_add_symbol;
  1767.       x->sub = exp->X_op_symbol;
  1768.       x->addnum = exp->X_add_number;
  1769.       x->added = 0;
  1770.       new_broken_words++;
  1771.       return;
  1772.     }
  1773. #endif
  1774.  
  1775.   /* If we have an integer, but the number of bytes is too large to
  1776.      pass to md_number_to_chars, handle it as a bignum.  */
  1777.   if (op == O_constant && nbytes > sizeof (valueT))
  1778.     {
  1779.       valueT val;
  1780.       int gencnt;
  1781.  
  1782.       if (! exp->X_unsigned && exp->X_add_number < 0)
  1783.     extra_digit = (valueT) -1;
  1784.       val = (valueT) exp->X_add_number;
  1785.       gencnt = 0;
  1786.       do
  1787.     {
  1788.       generic_bignum[gencnt] = val & LITTLENUM_MASK;
  1789.       val >>= LITTLENUM_NUMBER_OF_BITS;
  1790.       ++gencnt;
  1791.     }
  1792.       while (val != 0);
  1793.       op = exp->X_op = O_big;
  1794.       exp->X_add_number = gencnt;
  1795.     }
  1796.  
  1797.   if (op == O_constant)
  1798.     {
  1799.       register valueT get;
  1800.       register valueT use;
  1801.       register valueT mask;
  1802.       register valueT unmask;
  1803.  
  1804.       /* JF << of >= number of bits in the object is undefined.  In
  1805.      particular SPARC (Sun 4) has problems */
  1806.       if (nbytes >= sizeof (valueT))
  1807.     mask = 0;
  1808.       else
  1809.     mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);    /* Don't store these bits. */
  1810.  
  1811.       unmask = ~mask;        /* Do store these bits. */
  1812.  
  1813. #ifdef NEVER
  1814.       "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
  1815.       mask = ~(unmask >> 1);    /* Includes sign bit now. */
  1816. #endif
  1817.  
  1818.       get = exp->X_add_number;
  1819.       use = get & unmask;
  1820.       if ((get & mask) != 0 && (get & mask) != mask)
  1821.     {        /* Leading bits contain both 0s & 1s. */
  1822.       as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
  1823.     }
  1824.       /* put bytes in right order. */
  1825.       md_number_to_chars (p, use, (int) nbytes);
  1826.     }
  1827.   else if (op == O_big)
  1828.     {
  1829.       int size;
  1830.       LITTLENUM_TYPE *nums;
  1831.  
  1832.       know (nbytes % CHARS_PER_LITTLENUM == 0);
  1833.  
  1834.       size = exp->X_add_number * CHARS_PER_LITTLENUM;
  1835.       if (nbytes < size)
  1836.     {
  1837.       as_warn ("Bignum truncated to %d bytes", nbytes);
  1838.       size = nbytes;
  1839.     }
  1840.  
  1841.       if (target_big_endian)
  1842.     {
  1843.       while (nbytes > size)
  1844.         {
  1845.           md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
  1846.           nbytes -= CHARS_PER_LITTLENUM;
  1847.           p += CHARS_PER_LITTLENUM;
  1848.         }
  1849.  
  1850.       nums = generic_bignum + size / CHARS_PER_LITTLENUM;
  1851.       while (size > 0)
  1852.         {
  1853.           --nums;
  1854.           md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
  1855.           size -= CHARS_PER_LITTLENUM;
  1856.           p += CHARS_PER_LITTLENUM;
  1857.         }
  1858.     }
  1859.       else
  1860.     {
  1861.       nums = generic_bignum;
  1862.       while (size > 0)
  1863.         {
  1864.           md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
  1865.           ++nums;
  1866.           size -= CHARS_PER_LITTLENUM;
  1867.           p += CHARS_PER_LITTLENUM;
  1868.           nbytes -= CHARS_PER_LITTLENUM;
  1869.         }
  1870.  
  1871.       while (nbytes > 0)
  1872.         {
  1873.           md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
  1874.           nbytes -= CHARS_PER_LITTLENUM;
  1875.           p += CHARS_PER_LITTLENUM;
  1876.         }
  1877.     }
  1878.     }
  1879.   else
  1880.     {
  1881.       memset (p, 0, nbytes);
  1882.  
  1883.       /* Now we need to generate a fixS to record the symbol value.
  1884.      This is easy for BFD.  For other targets it can be more
  1885.      complex.  For very complex cases (currently, the HPPA and
  1886.      NS32K), you can define TC_CONS_FIX_NEW to do whatever you
  1887.      want.  For simpler cases, you can define TC_CONS_RELOC to be
  1888.      the name of the reloc code that should be stored in the fixS.
  1889.      If neither is defined, the code uses NO_RELOC if it is
  1890.      defined, and otherwise uses 0.  */
  1891.  
  1892. #ifdef BFD_ASSEMBLER
  1893. #ifdef TC_CONS_FIX_NEW
  1894.       TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
  1895. #else
  1896.       fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
  1897.            /* @@ Should look at CPU word size.  */
  1898.            nbytes == 2 ? BFD_RELOC_16
  1899.            : nbytes == 8 ? BFD_RELOC_64
  1900.            : BFD_RELOC_32);
  1901. #endif
  1902. #else
  1903. #ifdef TC_CONS_FIX_NEW
  1904.       TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
  1905. #else
  1906.       /* Figure out which reloc number to use.  Use TC_CONS_RELOC if
  1907.      it is defined, otherwise use NO_RELOC if it is defined,
  1908.      otherwise use 0.  */
  1909. #ifndef TC_CONS_RELOC
  1910. #ifdef NO_RELOC
  1911. #define TC_CONS_RELOC NO_RELOC
  1912. #else
  1913. #define TC_CONS_RELOC 0
  1914. #endif
  1915. #endif
  1916.       fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
  1917.            TC_CONS_RELOC);
  1918. #endif /* TC_CONS_FIX_NEW */
  1919. #endif /* BFD_ASSEMBLER */
  1920.     }
  1921. }
  1922.  
  1923. #ifdef BITFIELD_CONS_EXPRESSIONS
  1924.  
  1925. /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
  1926.    w:x,y:z, where w and y are bitwidths and x and y are values.  They
  1927.    then pack them all together. We do a little better in that we allow
  1928.    them in words, longs, etc. and we'll pack them in target byte order
  1929.    for you.
  1930.  
  1931.    The rules are: pack least significat bit first, if a field doesn't
  1932.    entirely fit, put it in the next unit.  Overflowing the bitfield is
  1933.    explicitly *not* even a warning.  The bitwidth should be considered
  1934.    a "mask".
  1935.  
  1936.    To use this function the tc-XXX.h file should define
  1937.    BITFIELD_CONS_EXPRESSIONS.  */
  1938.  
  1939. static void 
  1940. parse_bitfield_cons (exp, nbytes)
  1941.      expressionS *exp;
  1942.      unsigned int nbytes;
  1943. {
  1944.   unsigned int bits_available = BITS_PER_CHAR * nbytes;
  1945.   char *hold = input_line_pointer;
  1946.  
  1947.   (void) expression (exp);
  1948.  
  1949.   if (*input_line_pointer == ':')
  1950.     {            /* bitfields */
  1951.       long value = 0;
  1952.  
  1953.       for (;;)
  1954.     {
  1955.       unsigned long width;
  1956.  
  1957.       if (*input_line_pointer != ':')
  1958.         {
  1959.           input_line_pointer = hold;
  1960.           break;
  1961.         }            /* next piece is not a bitfield */
  1962.  
  1963.       /* In the general case, we can't allow
  1964.          full expressions with symbol
  1965.          differences and such.  The relocation
  1966.          entries for symbols not defined in this
  1967.          assembly would require arbitrary field
  1968.          widths, positions, and masks which most
  1969.          of our current object formats don't
  1970.          support.
  1971.          
  1972.          In the specific case where a symbol
  1973.          *is* defined in this assembly, we
  1974.          *could* build fixups and track it, but
  1975.          this could lead to confusion for the
  1976.          backends.  I'm lazy. I'll take any
  1977.          SEG_ABSOLUTE. I think that means that
  1978.          you can use a previous .set or
  1979.          .equ type symbol.  xoxorich. */
  1980.  
  1981.       if (exp->X_op == O_absent)
  1982.         {
  1983.           as_warn ("using a bit field width of zero");
  1984.           exp->X_add_number = 0;
  1985.           exp->X_op = O_constant;
  1986.         }            /* implied zero width bitfield */
  1987.  
  1988.       if (exp->X_op != O_constant)
  1989.         {
  1990.           *input_line_pointer = '\0';
  1991.           as_bad ("field width \"%s\" too complex for a bitfield", hold);
  1992.           *input_line_pointer = ':';
  1993.           demand_empty_rest_of_line ();
  1994.           return;
  1995.         }            /* too complex */
  1996.  
  1997.       if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
  1998.         {
  1999.           as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits",
  2000.                width, nbytes, (BITS_PER_CHAR * nbytes));
  2001.           width = BITS_PER_CHAR * nbytes;
  2002.         }            /* too big */
  2003.  
  2004.       if (width > bits_available)
  2005.         {
  2006.           /* FIXME-SOMEDAY: backing up and reparsing is wasteful.  */
  2007.           input_line_pointer = hold;
  2008.           exp->X_add_number = value;
  2009.           break;
  2010.         }            /* won't fit */
  2011.  
  2012.       hold = ++input_line_pointer; /* skip ':' */
  2013.  
  2014.       (void) expression (exp);
  2015.       if (exp->X_op != O_constant)
  2016.         {
  2017.           char cache = *input_line_pointer;
  2018.  
  2019.           *input_line_pointer = '\0';
  2020.           as_bad ("field value \"%s\" too complex for a bitfield", hold);
  2021.           *input_line_pointer = cache;
  2022.           demand_empty_rest_of_line ();
  2023.           return;
  2024.         }            /* too complex */
  2025.  
  2026.       value |= ((~(-1 << width) & exp->X_add_number)
  2027.             << ((BITS_PER_CHAR * nbytes) - bits_available));
  2028.  
  2029.       if ((bits_available -= width) == 0
  2030.           || is_it_end_of_statement ()
  2031.           || *input_line_pointer != ',')
  2032.         {
  2033.           break;
  2034.         }            /* all the bitfields we're gonna get */
  2035.  
  2036.       hold = ++input_line_pointer;
  2037.       (void) expression (exp);
  2038.     }            /* forever loop */
  2039.  
  2040.       exp->X_add_number = value;
  2041.       exp->X_op = O_constant;
  2042.       exp->X_unsigned = 1;
  2043.     }                /* if looks like a bitfield */
  2044. }                /* parse_bitfield_cons() */
  2045.  
  2046. #endif /* BITFIELD_CONS_EXPRESSIONS */
  2047.  
  2048. #ifdef MRI
  2049.  
  2050. static void
  2051. parse_mri_cons (exp, nbytes)
  2052.      expressionS *exp;
  2053.      unsigned int nbytes;
  2054. {
  2055.   if (*input_line_pointer == '\'')
  2056.     {
  2057.       /* An MRI style string, cut into as many bytes as will fit into
  2058.      a nbyte chunk, left justify if necessary, and separate with
  2059.      commas so we can try again later */
  2060.       int scan = 0;
  2061.       unsigned int result = 0;
  2062.       input_line_pointer++;
  2063.       for (scan = 0; scan < nbytes; scan++)
  2064.     {
  2065.       if (*input_line_pointer == '\'')
  2066.         {
  2067.           if (input_line_pointer[1] == '\'')
  2068.         {
  2069.           input_line_pointer++;
  2070.         }
  2071.           else
  2072.         break;
  2073.         }
  2074.       result = (result << 8) | (*input_line_pointer++);
  2075.     }
  2076.  
  2077.       /* Left justify */
  2078.       while (scan < nbytes)
  2079.     {
  2080.       result <<= 8;
  2081.       scan++;
  2082.     }
  2083.       /* Create correct expression */
  2084.       exp->X_op = O_constant;
  2085.       exp->X_add_number = result;
  2086.       /* Fake it so that we can read the next char too */
  2087.       if (input_line_pointer[0] != '\'' ||
  2088.       (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
  2089.     {
  2090.       input_line_pointer -= 2;
  2091.       input_line_pointer[0] = ',';
  2092.       input_line_pointer[1] = '\'';
  2093.     }
  2094.       else
  2095.     input_line_pointer++;
  2096.     }
  2097.   else
  2098.     expression (&exp);
  2099. }
  2100.  
  2101. #endif /* MRI */
  2102.  
  2103. #ifdef REPEAT_CONS_EXPRESSIONS
  2104.  
  2105. /* Parse a repeat expression for cons.  This is used by the MIPS
  2106.    assembler.  The format is NUMBER:COUNT; NUMBER appears in the
  2107.    object file COUNT times.
  2108.  
  2109.    To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
  2110.  
  2111. static void
  2112. parse_repeat_cons (exp, nbytes)
  2113.      expressionS *exp;
  2114.      unsigned int nbytes;
  2115. {
  2116.   expressionS count;
  2117.   register int i;
  2118.  
  2119.   expression (exp);
  2120.  
  2121.   if (*input_line_pointer != ':')
  2122.     {
  2123.       /* No repeat count.  */
  2124.       return;
  2125.     }
  2126.  
  2127.   ++input_line_pointer;
  2128.   expression (&count);
  2129.   if (count.X_op != O_constant
  2130.       || count.X_add_number <= 0)
  2131.     {
  2132.       as_warn ("Unresolvable or nonpositive repeat count; using 1");
  2133.       return;
  2134.     }
  2135.  
  2136.   /* The cons function is going to output this expression once.  So we
  2137.      output it count - 1 times.  */
  2138.   for (i = count.X_add_number - 1; i > 0; i--)
  2139.     emit_expr (exp, nbytes);
  2140. }
  2141.  
  2142. #endif /* REPEAT_CONS_EXPRESSIONS */
  2143.  
  2144. /*
  2145.  *            float_cons()
  2146.  *
  2147.  * CONStruct some more frag chars of .floats .ffloats etc.
  2148.  * Makes 0 or more new frags.
  2149.  * If need_pass_2 == 1, no frags are emitted.
  2150.  * This understands only floating literals, not expressions. Sorry.
  2151.  *
  2152.  * A floating constant is defined by atof_generic(), except it is preceded
  2153.  * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
  2154.  * reading, I decided to be incompatible. This always tries to give you
  2155.  * rounded bits to the precision of the pseudo-op. Former AS did premature
  2156.  * truncatation, restored noisy bits instead of trailing 0s AND gave you
  2157.  * a choice of 2 flavours of noise according to which of 2 floating-point
  2158.  * scanners you directed AS to use.
  2159.  *
  2160.  * In:    input_line_pointer->whitespace before, or '0' of flonum.
  2161.  *
  2162.  */
  2163.  
  2164. void
  2165. float_cons (float_type)
  2166.      /* Clobbers input_line-pointer, checks end-of-line. */
  2167.      register int float_type;    /* 'f':.ffloat ... 'F':.float ... */
  2168. {
  2169.   register char *p;
  2170.   int length;            /* Number of chars in an object. */
  2171.   register char *err;        /* Error from scanning floating literal. */
  2172.   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
  2173.  
  2174.   if (is_it_end_of_statement ())
  2175.     {
  2176.       demand_empty_rest_of_line ();
  2177.       return;
  2178.     }
  2179.  
  2180.   do
  2181.     {
  2182.       /* input_line_pointer->1st char of a flonum (we hope!). */
  2183.       SKIP_WHITESPACE ();
  2184.  
  2185.       /* Skip any 0{letter} that may be present. Don't even check if the
  2186.        * letter is legal. Someone may invent a "z" format and this routine
  2187.        * has no use for such information. Lusers beware: you get
  2188.        * diagnostics if your input is ill-conditioned.
  2189.        */
  2190.       if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
  2191.     input_line_pointer += 2;
  2192.  
  2193.       err = md_atof (float_type, temp, &length);
  2194.       know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
  2195.       know (length > 0);
  2196.       if (err)
  2197.     {
  2198.       as_bad ("Bad floating literal: %s", err);
  2199.       ignore_rest_of_line ();
  2200.       return;
  2201.     }
  2202.  
  2203.       if (!need_pass_2)
  2204.     {
  2205.       int count;
  2206.  
  2207.       count = 1;
  2208.  
  2209. #ifdef REPEAT_CONS_EXPRESSIONS
  2210.       if (*input_line_pointer == ':')
  2211.         {
  2212.           expressionS count_exp;
  2213.  
  2214.           ++input_line_pointer;
  2215.           expression (&count_exp);
  2216.           if (count_exp.X_op != O_constant
  2217.           || count_exp.X_add_number <= 0)
  2218.         {
  2219.           as_warn ("unresolvable or nonpositive repeat count; using 1");
  2220.         }
  2221.           else
  2222.         count = count_exp.X_add_number;
  2223.         }
  2224. #endif
  2225.  
  2226.       while (--count >= 0)
  2227.         {
  2228.           p = frag_more (length);
  2229.           memcpy (p, temp, (unsigned int) length);
  2230.         }
  2231.     }
  2232.       SKIP_WHITESPACE ();
  2233.     }
  2234.   while (*input_line_pointer++ == ',');
  2235.  
  2236.   --input_line_pointer;        /* Put terminator back into stream.  */
  2237.   demand_empty_rest_of_line ();
  2238. }                /* float_cons() */
  2239.  
  2240. /*
  2241.  *            stringer()
  2242.  *
  2243.  * We read 0 or more ',' seperated, double-quoted strings.
  2244.  *
  2245.  * Caller should have checked need_pass_2 is FALSE because we don't check it.
  2246.  */
  2247.  
  2248.  
  2249. void 
  2250. stringer (append_zero)        /* Worker to do .ascii etc statements. */
  2251.      /* Checks end-of-line. */
  2252.      register int append_zero;    /* 0: don't append '\0', else 1 */
  2253. {
  2254.   register unsigned int c;
  2255.  
  2256.   /*
  2257.    * The following awkward logic is to parse ZERO or more strings,
  2258.    * comma seperated. Recall a string expression includes spaces
  2259.    * before the opening '\"' and spaces after the closing '\"'.
  2260.    * We fake a leading ',' if there is (supposed to be)
  2261.    * a 1st, expression. We keep demanding expressions for each
  2262.    * ','.
  2263.    */
  2264.   if (is_it_end_of_statement ())
  2265.     {
  2266.       c = 0;            /* Skip loop. */
  2267.       ++input_line_pointer;    /* Compensate for end of loop. */
  2268.     }
  2269.   else
  2270.     {
  2271.       c = ',';            /* Do loop. */
  2272.     }
  2273.   while (c == ',' || c == '<' || c == '"')
  2274.     {
  2275.       SKIP_WHITESPACE ();
  2276.       switch (*input_line_pointer)
  2277.     {
  2278.     case '\"':
  2279.       ++input_line_pointer;    /*->1st char of string. */
  2280.       while (is_a_char (c = next_char_of_string ()))
  2281.         {
  2282.           FRAG_APPEND_1_CHAR (c);
  2283.         }
  2284.       if (append_zero)
  2285.         {
  2286.           FRAG_APPEND_1_CHAR (0);
  2287.         }
  2288.       know (input_line_pointer[-1] == '\"');
  2289.       break;
  2290.     case '<':
  2291.       input_line_pointer++;
  2292.       c = get_single_number ();
  2293.       FRAG_APPEND_1_CHAR (c);
  2294.       if (*input_line_pointer != '>')
  2295.         {
  2296.           as_bad ("Expected <nn>");
  2297.         }
  2298.       input_line_pointer++;
  2299.       break;
  2300.     case ',':
  2301.       input_line_pointer++;
  2302.       break;
  2303.     }
  2304.       SKIP_WHITESPACE ();
  2305.       c = *input_line_pointer;
  2306.     }
  2307.  
  2308.   demand_empty_rest_of_line ();
  2309. }                /* stringer() */
  2310.  
  2311. /* FIXME-SOMEDAY: I had trouble here on characters with the
  2312.     high bits set.  We'll probably also have trouble with
  2313.     multibyte chars, wide chars, etc.  Also be careful about
  2314.     returning values bigger than 1 byte.  xoxorich. */
  2315.  
  2316. unsigned int 
  2317. next_char_of_string ()
  2318. {
  2319.   register unsigned int c;
  2320.  
  2321.   c = *input_line_pointer++ & CHAR_MASK;
  2322.   switch (c)
  2323.     {
  2324.     case '\"':
  2325.       c = NOT_A_CHAR;
  2326.       break;
  2327.  
  2328. #ifndef NO_STRING_ESCAPES
  2329.     case '\\':
  2330.       switch (c = *input_line_pointer++)
  2331.     {
  2332.     case 'b':
  2333.       c = '\b';
  2334.       break;
  2335.  
  2336.     case 'f':
  2337.       c = '\f';
  2338.       break;
  2339.  
  2340.     case 'n':
  2341.       c = '\n';
  2342.       break;
  2343.  
  2344.     case 'r':
  2345.       c = '\r';
  2346.       break;
  2347.  
  2348.     case 't':
  2349.       c = '\t';
  2350.       break;
  2351.  
  2352. #ifdef BACKSLASH_V
  2353.     case 'v':
  2354.       c = '\013';
  2355.       break;
  2356. #endif
  2357.  
  2358.     case '\\':
  2359.     case '"':
  2360.       break;        /* As itself. */
  2361.  
  2362.     case '0':
  2363.     case '1':
  2364.     case '2':
  2365.     case '3':
  2366.     case '4':
  2367.     case '5':
  2368.     case '6':
  2369.     case '7':
  2370.     case '8':
  2371.     case '9':
  2372.       {
  2373.         long number;
  2374.         int i;
  2375.  
  2376.         for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
  2377.           {
  2378.         number = number * 8 + c - '0';
  2379.           }
  2380.         c = number & 0xff;
  2381.       }
  2382.       --input_line_pointer;
  2383.       break;
  2384.  
  2385.     case 'x':
  2386.     case 'X':
  2387.       {
  2388.         long number;
  2389.  
  2390.         number = 0;
  2391.         c = *input_line_pointer++;
  2392.         while (isxdigit (c))
  2393.           {
  2394.         if (isdigit (c))
  2395.           number = number * 16 + c - '0';
  2396.         else if (isupper (c))
  2397.           number = number * 16 + c - 'A' + 10;
  2398.         else
  2399.           number = number * 16 + c - 'a' + 10;
  2400.         c = *input_line_pointer++;
  2401.           }
  2402.         c = number & 0xff;
  2403.         --input_line_pointer;
  2404.       }
  2405.       break;
  2406.  
  2407.     case '\n':
  2408.       /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
  2409.       as_warn ("Unterminated string: Newline inserted.");
  2410.       c = '\n';
  2411.       break;
  2412.  
  2413.     default:
  2414.  
  2415. #ifdef ONLY_STANDARD_ESCAPES
  2416.       as_bad ("Bad escaped character in string, '?' assumed");
  2417.       c = '?';
  2418. #endif /* ONLY_STANDARD_ESCAPES */
  2419.  
  2420.       break;
  2421.     }            /* switch on escaped char */
  2422.       break;
  2423. #endif /* ! defined (NO_STRING_ESCAPES) */
  2424.  
  2425.     default:
  2426.       break;
  2427.     }                /* switch on char */
  2428.   return (c);
  2429. }                /* next_char_of_string() */
  2430.  
  2431. static segT
  2432. get_segmented_expression (expP)
  2433.      register expressionS *expP;
  2434. {
  2435.   register segT retval;
  2436.  
  2437.   retval = expression (expP);
  2438.   if (expP->X_op == O_illegal
  2439.       || expP->X_op == O_absent
  2440.       || expP->X_op == O_big)
  2441.     {
  2442.       as_bad ("expected address expression; zero assumed");
  2443.       expP->X_op = O_constant;
  2444.       expP->X_add_number = 0;
  2445.       retval = absolute_section;
  2446.     }
  2447.   return retval;
  2448. }
  2449.  
  2450. static segT 
  2451. get_known_segmented_expression (expP)
  2452.      register expressionS *expP;
  2453. {
  2454.   register segT retval;
  2455.  
  2456.   if ((retval = get_segmented_expression (expP)) == undefined_section)
  2457.     {
  2458.       /* There is no easy way to extract the undefined symbol from the
  2459.      expression.  */
  2460.       if (expP->X_add_symbol != NULL
  2461.       && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
  2462.     as_warn ("symbol \"%s\" undefined; zero assumed",
  2463.          S_GET_NAME (expP->X_add_symbol));
  2464.       else
  2465.     as_warn ("some symbol undefined; zero assumed");
  2466.       retval = absolute_section;
  2467.       expP->X_op = O_constant;
  2468.       expP->X_add_number = 0;
  2469.     }
  2470.   know (retval == absolute_section || SEG_NORMAL (retval));
  2471.   return (retval);
  2472. }                /* get_known_segmented_expression() */
  2473.  
  2474. offsetT
  2475. get_absolute_expression ()
  2476. {
  2477.   expressionS exp;
  2478.  
  2479.   expression (&exp);
  2480.   if (exp.X_op != O_constant)
  2481.     {
  2482.       if (exp.X_op != O_absent)
  2483.     as_bad ("bad absolute expression; zero assumed");
  2484.       exp.X_add_number = 0;
  2485.     }
  2486.   return exp.X_add_number;
  2487. }
  2488.  
  2489. char                /* return terminator */
  2490. get_absolute_expression_and_terminator (val_pointer)
  2491.      long *val_pointer;        /* return value of expression */
  2492. {
  2493.   /* FIXME: val_pointer should probably be offsetT *.  */
  2494.   *val_pointer = (long) get_absolute_expression ();
  2495.   return (*input_line_pointer++);
  2496. }
  2497.  
  2498. /*
  2499.  *            demand_copy_C_string()
  2500.  *
  2501.  * Like demand_copy_string, but return NULL if the string contains any '\0's.
  2502.  * Give a warning if that happens.
  2503.  */
  2504. char *
  2505. demand_copy_C_string (len_pointer)
  2506.      int *len_pointer;
  2507. {
  2508.   register char *s;
  2509.  
  2510.   if ((s = demand_copy_string (len_pointer)) != 0)
  2511.     {
  2512.       register int len;
  2513.  
  2514.       for (len = *len_pointer;
  2515.        len > 0;
  2516.        len--)
  2517.     {
  2518.       if (*s == 0)
  2519.         {
  2520.           s = 0;
  2521.           len = 1;
  2522.           *len_pointer = 0;
  2523.           as_bad ("This string may not contain \'\\0\'");
  2524.         }
  2525.     }
  2526.     }
  2527.   return (s);
  2528. }
  2529.  
  2530. /*
  2531.  *            demand_copy_string()
  2532.  *
  2533.  * Demand string, but return a safe (=private) copy of the string.
  2534.  * Return NULL if we can't read a string here.
  2535.  */
  2536. char *
  2537. demand_copy_string (lenP)
  2538.      int *lenP;
  2539. {
  2540.   register unsigned int c;
  2541.   register int len;
  2542.   char *retval;
  2543.  
  2544.   len = 0;
  2545.   SKIP_WHITESPACE ();
  2546.   if (*input_line_pointer == '\"')
  2547.     {
  2548.       input_line_pointer++;    /* Skip opening quote. */
  2549.  
  2550.       while (is_a_char (c = next_char_of_string ()))
  2551.     {
  2552.       obstack_1grow (¬es, c);
  2553.       len++;
  2554.     }
  2555.       /* JF this next line is so demand_copy_C_string will return a null
  2556.            termanated string. */
  2557.       obstack_1grow (¬es, '\0');
  2558.       retval = obstack_finish (¬es);
  2559.     }
  2560.   else
  2561.     {
  2562.       as_warn ("Missing string");
  2563.       retval = NULL;
  2564.       ignore_rest_of_line ();
  2565.     }
  2566.   *lenP = len;
  2567.   return (retval);
  2568. }                /* demand_copy_string() */
  2569.  
  2570. /*
  2571.  *        is_it_end_of_statement()
  2572.  *
  2573.  * In:    Input_line_pointer->next character.
  2574.  *
  2575.  * Do:    Skip input_line_pointer over all whitespace.
  2576.  *
  2577.  * Out:    1 if input_line_pointer->end-of-line.
  2578. */
  2579. int 
  2580. is_it_end_of_statement ()
  2581. {
  2582.   SKIP_WHITESPACE ();
  2583.   return (is_end_of_line[(unsigned char) *input_line_pointer]);
  2584. }                /* is_it_end_of_statement() */
  2585.  
  2586. void 
  2587. equals (sym_name)
  2588.      char *sym_name;
  2589. {
  2590.   register symbolS *symbolP;    /* symbol we are working with */
  2591.  
  2592.   input_line_pointer++;
  2593.   if (*input_line_pointer == '=')
  2594.     input_line_pointer++;
  2595.  
  2596.   while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
  2597.     input_line_pointer++;
  2598.  
  2599.   if (sym_name[0] == '.' && sym_name[1] == '\0')
  2600.     {
  2601.       /* Turn '. = mumble' into a .org mumble */
  2602.       register segT segment;
  2603.       expressionS exp;
  2604.       register char *p;
  2605.  
  2606.       segment = get_known_segmented_expression (&exp);
  2607.       if (!need_pass_2)
  2608.     {
  2609.       if (segment != now_seg && segment != absolute_section)
  2610.         as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
  2611.              segment_name (segment),
  2612.              segment_name (now_seg));
  2613.       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
  2614.             exp.X_add_number, (char *) 0);
  2615.       *p = 0;
  2616.     }            /* if (ok to make frag) */
  2617.     }
  2618.   else
  2619.     {
  2620.       symbolP = symbol_find_or_make (sym_name);
  2621.       pseudo_set (symbolP);
  2622.     }
  2623. }                /* equals() */
  2624.  
  2625. /* .include -- include a file at this point. */
  2626.  
  2627. /* ARGSUSED */
  2628. void 
  2629. s_include (arg)
  2630.      int arg;
  2631. {
  2632.   char *newbuf;
  2633.   char *filename;
  2634.   int i;
  2635.   FILE *try;
  2636.   char *path;
  2637.  
  2638.   filename = demand_copy_string (&i);
  2639.   demand_empty_rest_of_line ();
  2640.   path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
  2641.   for (i = 0; i < include_dir_count; i++)
  2642.     {
  2643.       strcpy (path, include_dirs[i]);
  2644.       strcat (path, "/");
  2645.       strcat (path, filename);
  2646.       if (0 != (try = fopen (path, "r")))
  2647.     {
  2648.       fclose (try);
  2649.       goto gotit;
  2650.     }
  2651.     }
  2652.   free (path);
  2653.   path = filename;
  2654. gotit:
  2655.   /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY. */
  2656.   newbuf = input_scrub_include_file (path, input_line_pointer);
  2657.   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2658. }                /* s_include() */
  2659.  
  2660. void 
  2661. add_include_dir (path)
  2662.      char *path;
  2663. {
  2664.   int i;
  2665.  
  2666.   if (include_dir_count == 0)
  2667.     {
  2668.       include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
  2669.       include_dirs[0] = ".";    /* Current dir */
  2670.       include_dir_count = 2;
  2671.     }
  2672.   else
  2673.     {
  2674.       include_dir_count++;
  2675.       include_dirs = (char **) realloc (include_dirs,
  2676.                 include_dir_count * sizeof (*include_dirs));
  2677.     }
  2678.  
  2679.   include_dirs[include_dir_count - 1] = path;    /* New one */
  2680.  
  2681.   i = strlen (path);
  2682.   if (i > include_dir_maxlen)
  2683.     include_dir_maxlen = i;
  2684. }                /* add_include_dir() */
  2685.  
  2686. void 
  2687. s_ignore (arg)
  2688.      int arg;
  2689. {
  2690.   while (!is_end_of_line[(unsigned char) *input_line_pointer])
  2691.     {
  2692.       ++input_line_pointer;
  2693.     }
  2694.   ++input_line_pointer;
  2695. }
  2696.  
  2697.  
  2698. /* end of read.c */
  2699.